var __UIMatchPlayerPanel_instance = null;
function getUIMatchPlayerPanel() { return __UIMatchPlayerPanel_instance; }

var UIMatchPlayerPanel = function(){};

UIMatchPlayerPanel.prototype.onDidLoadFromCCB = function()
{
    cc.log("UIMatchPlayerPanel.onDidLoadFromCCB");
    __UIMatchPlayerPanel_instance = this;

//    this.uiWindow.setPosition(0,0);
//    this.uiWindowText.setPosition(0,0);  
};

// 发送设置主界面数据
UIMatchPlayerPanel.prototype.setData = function(head, name, positon, txt1, txt2, isLeft)
{
    // 头像
    this.uiHead.init(head);
    // 大小缩放到80x80
    if (head) {
        this.uiHead.setVisible(true);
        s = this.uiHead.getContentSize();
        sx = 80/s.width;
        sy = 80/s.height;
        this.uiHead.setScale(Math.min(sx, sy));
    } else {
        this.uiHead.setVisible(false);
    }

    // 文字
    this.uiName.setString(name);
    this.uiPos.setString(positon);
    this.uiText1.setString(txt1);
    this.uiText2.setString(txt2);

    // 调整方向
    this.setSide(isLeft);
};


UIMatchPlayerPanel.prototype.setSide = function(isLeft) {
    this.uiLeft.setVisible(isLeft);
    this.uiRight.setVisible(!isLeft);

    var uis = [this.uiName, this.uiPos, this.uiText1, this.uiText2];

    if (isLeft) {
        for each (var ui in uis) {
            ui.setAnchorPoint(cc.p(0,0));
            ui.setPositionX(4);
        }
        this.uiHead.setPositionX(-42);

    } else {
        for each (var ui in uis) {
            ui.setAnchorPoint(cc.p(1,0));
            ui.setPositionX(-1);
        }
        this.uiHead.setPositionX(42);
    }
};



createUIMatchPlayerPanel = function(parent, uipos, head, name, matchpos, text1, text2) {
    panel = cc.BuilderReader.load("UIMatchPlayerPanel");
    panel.setPosition(uipos);
    panel.setAnchorPoint(cc.p(0,0));
    parent.addChild(panel);

    // PS:getUIMatchPlayerPanel()返回的只有最新的那一个
    getUIMatchPlayerPanel().setData(head, name, matchpos, text1, text2, true);
    return panel;
};